<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="${request.contextPath}/"/>
    <meta charset="UTF-8">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,minimum-scale=1.0">
    <title>社区报到</title>
    <link href="Content/wechat/css/reset.css" rel="stylesheet" type="text/css">
    <!--签到-->
    <link href="Content/wechat/css/dangJian_gongZhuGongJian_SQBD.css" rel="stylesheet" type="text/css">

    <script src="Content/wechat/js/jquery.min.js"></script>
    <!--字体缩放-->
    <script src="Content/wechat/js/ziti.js"></script>
    <!--验证工具引入的js-->
    <script src="Content/wechat/js/jquery.validate.js"></script>
    <!--上传图片js-->
    <script  src="Content/wechat/js/svg.js"></script>
    <!--end 上传图片js-->
</head>
<body>
<!--<header class="clearfix">-->
<!--    <h2>社区报到</h2><button class="quxiao_btn">取消</button>-->
<!--</header>-->
<div class="xinyuan">
    <form id="form">
    <div class="xinyuan_box">

        <dl class="clearfix">
            <dt>姓名</dt>
            <dd>
                <input class="text" type="text" name="reportname" id="reportname" placeholder="请输入姓名">
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>电话</dt>
            <dd>
                <input class="text" type="text" name="reportphone" id="reportphone" placeholder="请输入电话">
                <label hidden="hidden" id="realizename-errorsj" class="error" ></label>
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>住址</dt>
            <dd>
                <input class="text" type="text" name="address" id="address" placeholder="请输入住址">
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>身份证号</dt>
            <dd>
                <input class="text" type="text" name="idnumber" id="idnumber" placeholder="请输入身份证号">
                <label hidden="hidden" id="realizename-errorsj1" class="error" ></label>
                <label hidden="hidden" id="realizename-errorsj2" class="error" ></label>
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>所在社区</dt>
            <dd>
                <select id="shequ" name="">
                <!--<option id="shequ">-&#45;&#45;请选择-&#45;&#45;</option>-->
                </select>
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>小区名称</dt>
            <dd><select id="xiaoqu" name="">
                <!--<option>-&#45;&#45;请选择社区-&#45;&#45;</option>-->
            </select>
            </dd>
        </dl>
        <dl class="clearfix">
            <dt>单位名称</dt>
            <dd><select id="danwei" name="companyid">
                <!--<option>-&#45;&#45;法律服务-&#45;&#45;</option>-->
            </select>
            </dd>
        </dl>


        <h4>报到内容：</h4>
        <textarea class="textarea" name="content" id="content" placeholder="请简要说明"></textarea>
        <!--上传多张图片-->
    </div>
    </form>
    <div class="button_shangChuan" type="button" id="submit">确定</div>
</div>
</body>

<script>
    $(document).ready(function(e) {
        shequ();//加载社区的数据
        xiaoqu();//加载小区的数据
        danwei();//加载单位的数据

    // 当社区发生变化
        $("#shequ").change(function(){
            xiaoqu();
            danwei();
        })
        //当小区发生改变
        $("#xiaoqu").change(function(){
            danwei();
        })
    });
    function shequ() {
        var pcode = "0001"; //找出社区的父级代号
        $.ajax({
            async:false,//同步
            url:"wechat/home/party/report/ajax_shequ",
            data:{pcode:pcode},
            type:"POST",
            dataType:"JSON",
            success: function(data){
                var str = "";
                for(var i=0;i<data.data.length;i++) {
                    str += "<option value='"+data.data[i].id+"'>"+data.data[i].communityname+"</option>";
                }
                $("#shequ").html(str);
            }
        });
    }
    //加载小区
    function xiaoqu() {
        //根据父级代号
        //取父级代号
        var pcode = $("#shequ").val();
        //根据父级代号查数据
        $.ajax({
            async:false,
            //取消异步
            url:"wechat/home/party/report/ajax_xiaoqu",
            data:{pcode:pcode},
            type:"POST",
            dataType:"JSON",
            success:function(data) {
                var str = "";
                for(var i=0;i<data.data.length;i++) {
                    str += "<option value='"+data.data[i].id+"'>"+data.data[i].villagename+"</option>";
                }
                $("#xiaoqu").html(str);
            }
        });
    }
    //加载单位
    function danwei() {
        //根据父级代号
        //取父级代号
        var pcode = $("#xiaoqu").val();
        //根据父级代号查数据
        $.ajax({
            url:"wechat/home/party/report/ajax_danwei",
            data:{pcode:pcode},
            type:"POST",
            dataType:"JSON",
            success:function(data) {
                var str = "";
                for(var i=0;i<data.data.length;i++) {
                    str += "<option value='"+data.data[i].id+"'>"+data.data[i].companyname+"</option>";
                }
                $("#danwei").html(str);
            }
        });
    }
</script>
<script type="text/javascript">
    $().ready(function () {
        $("#submit").click(function(){
            //        if( $("input[name='wishname']").val() == ""||  $("input[name='wishname']").val().length ==0){
            //            alert("心愿不能为空");
            //            $("input[name='wishname']").focus();
            //            return;
            //        }
            var reportphone = document.getElementById('reportphone').value;
            if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(reportphone))){
                $("#realizename-errorsj").html("请输入正确的手机号格式");
                return false;
            }
            var idnumber = document.getElementById('idnumber').value;
            if(!(/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(idnumber))){
                $("#realizename-errorsj1").html("请输入正确的身份证格式");
                $("#realizename-errorsj2").html("");
                return false;
            }

            $.ajax({
                url: "wechat/home/party/report/ajax_shequ_baodao",
                type: 'POST',
                async: false,
                dataType:"json",
                data:{"idnumber":idnumber},
                success:function (msg) {
                    if (msg == "1"){
//                        top.dialogTop("已经参加过报到", 'error');
//                        alert("已经参加过报到");
                        $("#realizename-errorsj1").html("");
                        $("#realizename-errorsj2").html("已经参加过报到");
                        flag = false;
                        return false;
                    }else{
                        flag = true;
                        return true;
                    }
                },
            })
            if(flag == false){
                return false;
            }

            if ($("#form").valid()) {
                var loadingIndex = null;
                $.ajax({
                    url: "wechat/home/party/report/saveForm",
                    type: "POST",
                    data: $("#form").serialize(),
                    success: function () {
                        window.location.href = "wechat/home/party/report/report_index"
                    }
                })
            }
        })
        $("#form").validate({
            rules: {
                reportname: {
                    required: true,
                    minlength: 2,
                    maxlength: 50,

                },
                content: {
                    required: true,
                    minlength: 5,
                    maxlength: 500,
                }
            },
            messages: {
                reportname: {
                    minlength: "(字符不能少于 2 个且不能大于 50个)",
                    maxlength: "(字符不能少于 2 个且不能大于 50个)",
                },
                content: {
                    minlength: "(字符不能少于 5 个且不能大于 500个)",
                    maxlength: "(字符不能少于 5 个且不能大于 500个)",
                }
            }
        })
    });
</script>

</html>
